
<template>
  <div>
    <el-table :border="true" :data="dataSource">
      <el-table-column type="index" label="#" fixed />
      <el-table-column prop="yearTarget_name" label="名称" fixed>
        <template slot-scope="scope">
          <span v-if="scope.row.yearTarget_name !== '汇总'">{{ scope.row.project_name+'-'+ scope.row.month}}</span>
          <span v-else>{{ scope.row.yearTarget_name }}</span>
        </template>
    </el-table-column>
      <el-table-column prop="businessIncomeTotalIndex" width="180" label="年度营业收入指标(万元)">
        <template slot-scope="scope">
          <span>{{ parseInt(scope.row.businessIncomeTotalIndex) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="businessIncomeTotal"  label="本年累计营业收入(万元)" >
        <template slot-scope="scope">
          <span>{{ parseInt(scope.row.businessIncomeTotal) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="annualOperatingRevenueCompletionRate"  label="年度营业收入完成率">
        <template slot-scope="scope">
          <span>{{ parseInt(scope.row.annualOperatingRevenueCompletionRate) }}%</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="businessIncomeTarget" width="180" label="月度营业收入指标(万元)" />
      <el-table-column prop="operatingRevenueProgress" width="180" label="营业收入节点进度" />
      <el-table-column prop="operatingIncomeGap" width="180" label="营业收入差距(万元)" /> -->
      <el-table-column prop="netProfitTotalIndex"  label="年度净利润指标(万元)">
        <template slot-scope="scope">
          <span>{{ parseInt(scope.row.netProfitTotalIndex) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="netProfitTotal"  label="本年累计净利润(万元)">
        <template slot-scope="scope">
          <span>{{ parseInt(scope.row.netProfitTotal) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="annualNetProfitCompletionRate" label="年度净利润完成率">
        <template slot-scope="scope">
          <span>{{ parseInt(scope.row.annualNetProfitCompletionRate) }}%</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="netProfitTarget" width="180" label="月度净利润指标(万元)" />
      <el-table-column prop="netProfitProgress" width="180" label="净利润节点进度" />
      <el-table-column prop="netProfitGap" width="180" label="净利润差距(万元)" /> -->
      <!-- <el-table-column prop="consolidatedRevenueTotal" width="180" label="本年累计并表营收(万元)" />
      <el-table-column prop="consolidatedRevenueTotalIndex" width="180" label="年度并表营收指标(万元)" />
      <el-table-column prop="annualConsolidatedRevenueCompletionRate" width="180" label="年度并表营收完成率">
        <template slot-scope="scope">
          <span>{{ scope.row.annualOperatingRevenueCompletionRate }}%</span>
        </template>
      </el-table-column>
      <el-table-column prop="consolidatedRevenueTarget" width="180" label="月度并表营收指标(万元)" />
      <el-table-column prop="consolidatedRevenueProgress" width="180" label="并表营收节点进度" />
      <el-table-column prop="consolidatedRevenueGap" width="180" label="并表营收差距(万元)" /> -->
    </el-table>
  </div>
</template>

<script>
export default {
  props: ["tableData"],
  watch: {
    tableData: {
      handler(){
        this.countTotal()
      },
      deep: true
    }
  },
  data(){
    return {
      dataSource: []
    }
  },
  methods: {
    countTotal(){
        let tableData = this.tableData || []
        let totalObj = {
          businessIncomeTotalIndex: 0,
          businessIncomeTotal:0,
          // annualOperatingRevenueCompletionRate:0, 年度收入完成率
          netProfitTotalIndex: 0,
          netProfitTotal:0,
          // annualNetProfitCompletionRate:0 利润完成率
        }
        tableData.forEach((item,index)=>{
            for(let key in totalObj){
                totalObj[key] = totalObj[key] + (item[key]||0)
            }
        })
        totalObj['yearTarget_name'] = '汇总'
        totalObj['annualOperatingRevenueCompletionRate'] = totalObj.businessIncomeTotal/totalObj.businessIncomeTotalIndex*100
        totalObj['annualNetProfitCompletionRate'] = totalObj.netProfitTotal/totalObj.netProfitTotalIndex *100
        let dataSource = [...tableData]
        dataSource.push(totalObj)
        this.dataSource = dataSource
        // this.tableData.push(totalObj)
        console.log('tableData---------', dataSource)
    }
  }
};
</script>

<style>
</style>